package cn.melonlib.cores.commons.comp.utils;

import lombok.Getter;

import java.util.Objects;
import java.util.function.Function;

@Getter
public class DistinctMapper<MAP> {

    private MAP map;

    private Function<MAP,Integer> hash;

    public DistinctMapper(MAP map, Function<MAP,Integer> hash){
        this.map=map;
        this.hash=hash;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof DistinctMapper)) return false;
        DistinctMapper<?> that = (DistinctMapper<?>) o;
        return Objects.equals(this.hashCode(), that.hashCode());
    }

    @Override
    public int hashCode() {
        return hash.apply(map);
    }
}
